package com.g001.model;

import java.util.HashMap;
import java.util.UUID;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.enums.BlockType;
import com.g001.enums.MovingBlockType;
import com.g001.enums.ProxBlockType;

public class BorderBlock extends IBlock {

	
	public BorderBlock(final int i, final int j, final Vector2f gamePosition) throws SlickException {
		this.blockType = BlockType.BORDER;
		this.i = i;
		this.j = j;
		this.shape = new Polygon(BlockType.tab);
		this.gamePosition = gamePosition;
		movingBlockType = MovingBlockType.X_Y; // no mvt
		setProxiBlocks(new HashMap<ProxBlockType,IBlock>());
		this.id = UUID.randomUUID();
		initPosition();
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		// TODO Auto-generated method stub
//		g.draw(shape);
//		g.setColor(Color.white);
//		g.drawString(i+","+j, x+15, y+20);
	}
	
	
	protected void initPosition(){
		if(i%2==1) {
				 x = i * BlockType.WIDTH  + gamePosition.x;// + i*BlockType.WIDTH/4;
				 y = j * BlockType.HEIGHT + gamePosition.y + BlockType.HEIGHT/2;
		} else {
				x = i * BlockType.WIDTH  + gamePosition.x ; 
				y = j * BlockType.HEIGHT + gamePosition.y;
		}
		x = x - i * 20;
		updateShape();
	}

	@Override
	public void setSelected(boolean b) {
		// no selection
	}
	
	public String toString(){
		return  "["+i+","+j+"]"+String.valueOf(blockType)+" "+getId();
	}

	@Override
	public boolean isSelected() {
		return false;
	}

	@Override
	public void setShock() {
	}
	
	@Override
	public void moveTo(final IBlock b){
	}

	@Override
	public boolean isSwitching() {
		return false;
	}

	@Override
	public void setSwitching(boolean switching) {
		
	}

	@Override
	public void moveBack(IBlock b) {
	}

	@Override
	public boolean isProxyUpdated() {
		return true;
	}

	@Override
	public void setProxyUpdated(boolean proxyUpdated) {
	}

	public int numberOfSouthBlocks(IBlock block){
		if(block == null) return 0;
		return 1 + numberOfSouthBlocks(block.getProxyBlock(ProxBlockType.S));
	}

	@Override
	public void setRemove(boolean b) {
		matchesChecked = true;
	}

	@Override
	public boolean isFalling() {
		return false;
	}

	@Override
	public boolean isBusy() {
		// never busy
		return false;
	}
}
